/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.vportal.portlet.vlinksman.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.vportal.portlet.vlinksman.model.Links;
import com.vportal.portlet.vlinksman.model.LinksModel;
import com.vportal.portlet.vlinksman.model.LinksSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The base model implementation for the Links service. Represents a row in the &quot;Links&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.vportal.portlet.vlinksman.model.LinksModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link LinksImpl}.
 * </p>
 *
 * @author LongLH
 * @see LinksImpl
 * @see com.vportal.portlet.vlinksman.model.Links
 * @see com.vportal.portlet.vlinksman.model.LinksModel
 * @generated
 */
@JSON(strict = true)
public class LinksModelImpl extends BaseModelImpl<Links> implements LinksModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a links model instance should use the {@link com.vportal.portlet.vlinksman.model.Links} interface instead.
	 */
	public static final String TABLE_NAME = "Links";
	public static final Object[][] TABLE_COLUMNS = {
			{ "linkId", Types.BIGINT },
			{ "groupId", Types.BIGINT },
			{ "companyId", Types.BIGINT },
			{ "createdDate", Types.TIMESTAMP },
			{ "modifiedDate", Types.TIMESTAMP },
			{ "linkgroupId", Types.BIGINT },
			{ "name", Types.VARCHAR },
			{ "description", Types.VARCHAR },
			{ "url", Types.VARCHAR },
			{ "position", Types.BIGINT },
			{ "hasImage", Types.BOOLEAN },
			{ "isTargetBlank", Types.BOOLEAN },
			{ "imageName", Types.VARCHAR },
			{ "folderId", Types.BIGINT }
		};
	public static final String TABLE_SQL_CREATE = "create table Links (linkId LONG not null primary key,groupId LONG,companyId LONG,createdDate DATE null,modifiedDate DATE null,linkgroupId LONG,name VARCHAR(75) null,description VARCHAR(250) null,url VARCHAR(250) null,position LONG,hasImage BOOLEAN,isTargetBlank BOOLEAN,imageName VARCHAR(75) null,folderId LONG)";
	public static final String TABLE_SQL_DROP = "drop table Links";
	public static final String ORDER_BY_JPQL = " ORDER BY links.position ASC";
	public static final String ORDER_BY_SQL = " ORDER BY Links.position ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.vportal.portlet.vlinksman.model.Links"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.vportal.portlet.vlinksman.model.Links"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.vportal.portlet.vlinksman.model.Links"),
			true);
	public static long GROUPID_COLUMN_BITMASK = 1L;
	public static long LINKGROUPID_COLUMN_BITMASK = 2L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Links toModel(LinksSoap soapModel) {
		Links model = new LinksImpl();

		model.setLinkId(soapModel.getLinkId());
		model.setGroupId(soapModel.getGroupId());
		model.setCompanyId(soapModel.getCompanyId());
		model.setCreatedDate(soapModel.getCreatedDate());
		model.setModifiedDate(soapModel.getModifiedDate());
		model.setLinkgroupId(soapModel.getLinkgroupId());
		model.setName(soapModel.getName());
		model.setDescription(soapModel.getDescription());
		model.setUrl(soapModel.getUrl());
		model.setPosition(soapModel.getPosition());
		model.setHasImage(soapModel.getHasImage());
		model.setIsTargetBlank(soapModel.getIsTargetBlank());
		model.setImageName(soapModel.getImageName());
		model.setFolderId(soapModel.getFolderId());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Links> toModels(LinksSoap[] soapModels) {
		List<Links> models = new ArrayList<Links>(soapModels.length);

		for (LinksSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.vportal.portlet.vlinksman.model.Links"));

	public LinksModelImpl() {
	}

	public long getPrimaryKey() {
		return _linkId;
	}

	public void setPrimaryKey(long primaryKey) {
		setLinkId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_linkId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Links.class;
	}

	public String getModelClassName() {
		return Links.class.getName();
	}

	@JSON
	public long getLinkId() {
		return _linkId;
	}

	public void setLinkId(long linkId) {
		_linkId = linkId;
	}

	@JSON
	public long getGroupId() {
		return _groupId;
	}

	public void setGroupId(long groupId) {
		_columnBitmask |= GROUPID_COLUMN_BITMASK;

		if (!_setOriginalGroupId) {
			_setOriginalGroupId = true;

			_originalGroupId = _groupId;
		}

		_groupId = groupId;
	}

	public long getOriginalGroupId() {
		return _originalGroupId;
	}

	@JSON
	public long getCompanyId() {
		return _companyId;
	}

	public void setCompanyId(long companyId) {
		_companyId = companyId;
	}

	@JSON
	public Date getCreatedDate() {
		return _createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		_createdDate = createdDate;
	}

	@JSON
	public Date getModifiedDate() {
		return _modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		_modifiedDate = modifiedDate;
	}

	@JSON
	public long getLinkgroupId() {
		return _linkgroupId;
	}

	public void setLinkgroupId(long linkgroupId) {
		_columnBitmask |= LINKGROUPID_COLUMN_BITMASK;

		if (!_setOriginalLinkgroupId) {
			_setOriginalLinkgroupId = true;

			_originalLinkgroupId = _linkgroupId;
		}

		_linkgroupId = linkgroupId;
	}

	public long getOriginalLinkgroupId() {
		return _originalLinkgroupId;
	}

	@JSON
	public String getName() {
		if (_name == null) {
			return StringPool.BLANK;
		}
		else {
			return _name;
		}
	}

	public void setName(String name) {
		_name = name;
	}

	@JSON
	public String getDescription() {
		if (_description == null) {
			return StringPool.BLANK;
		}
		else {
			return _description;
		}
	}

	public void setDescription(String description) {
		_description = description;
	}

	@JSON
	public String getUrl() {
		if (_url == null) {
			return StringPool.BLANK;
		}
		else {
			return _url;
		}
	}

	public void setUrl(String url) {
		_url = url;
	}

	@JSON
	public long getPosition() {
		return _position;
	}

	public void setPosition(long position) {
		_columnBitmask = -1L;

		_position = position;
	}

	@JSON
	public boolean getHasImage() {
		return _hasImage;
	}

	public boolean isHasImage() {
		return _hasImage;
	}

	public void setHasImage(boolean hasImage) {
		_hasImage = hasImage;
	}

	@JSON
	public boolean getIsTargetBlank() {
		return _isTargetBlank;
	}

	public boolean isIsTargetBlank() {
		return _isTargetBlank;
	}

	public void setIsTargetBlank(boolean isTargetBlank) {
		_isTargetBlank = isTargetBlank;
	}

	@JSON
	public String getImageName() {
		if (_imageName == null) {
			return StringPool.BLANK;
		}
		else {
			return _imageName;
		}
	}

	public void setImageName(String imageName) {
		_imageName = imageName;
	}

	@JSON
	public long getFolderId() {
		return _folderId;
	}

	public void setFolderId(long folderId) {
		_folderId = folderId;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public Links toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Links)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		if (_expandoBridge == null) {
			_expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
					Links.class.getName(), getPrimaryKey());
		}

		return _expandoBridge;
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		getExpandoBridge().setAttributes(serviceContext);
	}

	@Override
	public Object clone() {
		LinksImpl linksImpl = new LinksImpl();

		linksImpl.setLinkId(getLinkId());
		linksImpl.setGroupId(getGroupId());
		linksImpl.setCompanyId(getCompanyId());
		linksImpl.setCreatedDate(getCreatedDate());
		linksImpl.setModifiedDate(getModifiedDate());
		linksImpl.setLinkgroupId(getLinkgroupId());
		linksImpl.setName(getName());
		linksImpl.setDescription(getDescription());
		linksImpl.setUrl(getUrl());
		linksImpl.setPosition(getPosition());
		linksImpl.setHasImage(getHasImage());
		linksImpl.setIsTargetBlank(getIsTargetBlank());
		linksImpl.setImageName(getImageName());
		linksImpl.setFolderId(getFolderId());

		linksImpl.resetOriginalValues();

		return linksImpl;
	}

	public int compareTo(Links links) {
		int value = 0;

		if (getPosition() < links.getPosition()) {
			value = -1;
		}
		else if (getPosition() > links.getPosition()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Links links = null;

		try {
			links = (Links)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = links.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		LinksModelImpl linksModelImpl = this;

		linksModelImpl._originalGroupId = linksModelImpl._groupId;

		linksModelImpl._setOriginalGroupId = false;

		linksModelImpl._originalLinkgroupId = linksModelImpl._linkgroupId;

		linksModelImpl._setOriginalLinkgroupId = false;

		linksModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Links> toCacheModel() {
		LinksCacheModel linksCacheModel = new LinksCacheModel();

		linksCacheModel.linkId = getLinkId();

		linksCacheModel.groupId = getGroupId();

		linksCacheModel.companyId = getCompanyId();

		Date createdDate = getCreatedDate();

		if (createdDate != null) {
			linksCacheModel.createdDate = createdDate.getTime();
		}
		else {
			linksCacheModel.createdDate = Long.MIN_VALUE;
		}

		Date modifiedDate = getModifiedDate();

		if (modifiedDate != null) {
			linksCacheModel.modifiedDate = modifiedDate.getTime();
		}
		else {
			linksCacheModel.modifiedDate = Long.MIN_VALUE;
		}

		linksCacheModel.linkgroupId = getLinkgroupId();

		linksCacheModel.name = getName();

		String name = linksCacheModel.name;

		if ((name != null) && (name.length() == 0)) {
			linksCacheModel.name = null;
		}

		linksCacheModel.description = getDescription();

		String description = linksCacheModel.description;

		if ((description != null) && (description.length() == 0)) {
			linksCacheModel.description = null;
		}

		linksCacheModel.url = getUrl();

		String url = linksCacheModel.url;

		if ((url != null) && (url.length() == 0)) {
			linksCacheModel.url = null;
		}

		linksCacheModel.position = getPosition();

		linksCacheModel.hasImage = getHasImage();

		linksCacheModel.isTargetBlank = getIsTargetBlank();

		linksCacheModel.imageName = getImageName();

		String imageName = linksCacheModel.imageName;

		if ((imageName != null) && (imageName.length() == 0)) {
			linksCacheModel.imageName = null;
		}

		linksCacheModel.folderId = getFolderId();

		return linksCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(29);

		sb.append("{linkId=");
		sb.append(getLinkId());
		sb.append(", groupId=");
		sb.append(getGroupId());
		sb.append(", companyId=");
		sb.append(getCompanyId());
		sb.append(", createdDate=");
		sb.append(getCreatedDate());
		sb.append(", modifiedDate=");
		sb.append(getModifiedDate());
		sb.append(", linkgroupId=");
		sb.append(getLinkgroupId());
		sb.append(", name=");
		sb.append(getName());
		sb.append(", description=");
		sb.append(getDescription());
		sb.append(", url=");
		sb.append(getUrl());
		sb.append(", position=");
		sb.append(getPosition());
		sb.append(", hasImage=");
		sb.append(getHasImage());
		sb.append(", isTargetBlank=");
		sb.append(getIsTargetBlank());
		sb.append(", imageName=");
		sb.append(getImageName());
		sb.append(", folderId=");
		sb.append(getFolderId());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(46);

		sb.append("<model><model-name>");
		sb.append("com.vportal.portlet.vlinksman.model.Links");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>linkId</column-name><column-value><![CDATA[");
		sb.append(getLinkId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>groupId</column-name><column-value><![CDATA[");
		sb.append(getGroupId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>companyId</column-name><column-value><![CDATA[");
		sb.append(getCompanyId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createdDate</column-name><column-value><![CDATA[");
		sb.append(getCreatedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
		sb.append(getModifiedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>linkgroupId</column-name><column-value><![CDATA[");
		sb.append(getLinkgroupId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>name</column-name><column-value><![CDATA[");
		sb.append(getName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>description</column-name><column-value><![CDATA[");
		sb.append(getDescription());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>url</column-name><column-value><![CDATA[");
		sb.append(getUrl());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>position</column-name><column-value><![CDATA[");
		sb.append(getPosition());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>hasImage</column-name><column-value><![CDATA[");
		sb.append(getHasImage());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>isTargetBlank</column-name><column-value><![CDATA[");
		sb.append(getIsTargetBlank());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>imageName</column-name><column-value><![CDATA[");
		sb.append(getImageName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>folderId</column-name><column-value><![CDATA[");
		sb.append(getFolderId());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Links.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Links.class
		};
	private long _linkId;
	private long _groupId;
	private long _originalGroupId;
	private boolean _setOriginalGroupId;
	private long _companyId;
	private Date _createdDate;
	private Date _modifiedDate;
	private long _linkgroupId;
	private long _originalLinkgroupId;
	private boolean _setOriginalLinkgroupId;
	private String _name;
	private String _description;
	private String _url;
	private long _position;
	private boolean _hasImage;
	private boolean _isTargetBlank;
	private String _imageName;
	private long _folderId;
	private transient ExpandoBridge _expandoBridge;
	private long _columnBitmask;
	private Links _escapedModelProxy;
}